package progetto;

import example.hot.InetCoordinates;
import peersim.config.Configuration;
import peersim.core.Control;
import peersim.core.Network;
import peersim.core.Node;
import peersim.vector.SingleValueHolder;
import progetto.BluetoothTransm;
import progetto.LocalView;

public class LocalViewInit implements Control {

	// ------------------------------------------------------------------------
    // Parameters
    // ------------------------------------------------------------------------
    
	/**
	 * 
	 */
	//private static final String PAR_SQUARE_PROT = "ss_protocol"; 
	
	
    /**
     * The coordinate protocol to look at.
     * 
     * @config
     */
    private static final String PAR_COORD_PROT = "coord_protocol";
    
    /**
     * 
     * 
     * @config
     */
    private static final String PAR_LV_PROT = "lv_protocol";
    

   /**
    * @config
    */
    //private static final String PAR_BT_PROT = "protocol";
   
    // ------------------------------------------------------------------------
    // Fields
    // ------------------------------------------------------------------------

    /**
     * Obtained from config property
     * {@link #PAR_LV_PROT}.
     */
    private final int lvPid;
    
     
        
    

  
    
    /**
     * {@link #PAR_BT_PROT}
     *//*
    private final int blueTPid;
	 */
    /**
     * 
     */
    private final int coordPid;
    
    
    
    /**
     * Size of the slice of the square
     * Obtained from the config property
     * {@link #SIZE_SQUARE}.
     */
    //private final double sizeSquare;
    
    // ------------------------------------------------------------------------
    // Constructor
    // ------------------------------------------------------------------------
    /**
     * Standard constructor that reads the configuration parameters. Normally
     * invoked by the simulation engine.
     * 
     * @param prefix
     *            the configuration prefix for this class
     */
    public LocalViewInit(String prefix) {
	     lvPid = Configuration.getPid(prefix + "." + PAR_LV_PROT);
	     coordPid = Configuration.getPid(prefix + "." + PAR_COORD_PROT);
	     //ssPid = Configuration.getPid(prefix + "."+ PAR_SQUARE_PROT);
	     
	     
	    //sizeSquare = Configuration.getDouble(prefix + "." + SIZE_SQUARE, DEFAULT_SQUARE);
	     
	    // blueTPid = Configuration.getPid(prefix + "." + PAR_BT_PROT);
	     //radiusNormal = getNormalizedValue(radius, sizeSquare);
	     
	     
	     
    }
	
    // ----------------------------------------------------------------------
    // Methods
    // ----------------------------------------------------------------------

   
    
    
	@Override
	public boolean execute() {
	
		
		
		for(int i=0; i<Network.size(); i++) {
			Node node = Network.get(i);
			
			BluetoothTransm bt = BluetoothTransm.getInstance();
			//double valueSquare = ((SquareSize)node.getProtocol(ssPid)).getSize();
			//bt.setRadius(getNormalizedValue(radius, valueSquare));
			InetCoordinates coordProt = (InetCoordinates)node.getProtocol(coordPid);
			
			for(int j=0; j<Network.size(); j++) {
				Node current = Network.get(j);
				if(!node.equals(current) && bt.inTheTrasmRadius(node, current, coordPid)) {
					LocalView lvProt =  (LocalView)node.getProtocol(lvPid);
					lvProt.addNeighbor(current);
				}
				
				
			}
		}
		
		return false;
	}
	
	


}
